<?php

//session_start();

$conn = new Connection();
$categories = $conn->fetchCategory($_SESSION['LOGIN_INFO']['id']);
$categories = urldecode($categories);
$categories = json_decode($categories, true);
$sub_categories = $conn->fetchSubCategory($_SESSION['LOGIN_INFO']['id']);
$sub_categories = urldecode($sub_categories);
$sub_categories = json_decode($sub_categories, true);

//echo "<pre>";print_r($sub_categories);echo "</pre>";exit;

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-TW" lang="zh-TW">

<head>
  <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" /> 
  <link rel="stylesheet" type="text/css" href="styles/css/html.css" media="screen, projection, tv " />
  <link rel="stylesheet" type="text/css" href="styles/css/layout.css" media="screen, projection, tv" />
  <link rel="stylesheet" type="text/css" href="styles/css/print.css" media="print" />
  <link rel="stylesheet" type="text/css" href="styles/css/jquery.fancybox-1.3.1.css"  />
  <script src="styles/js/jquery.js" type="text/javascript"></script>
  <script src="styles/js/ajax.js" type="text/javascript"></script>
  <script src="styles/js/ulikewall.js" type="text/javascript"></script>
  <script src="styles/js/jquery.fancybox-1.3.1.pack.js" type="text/javascript"></script>
  <script src="https://www.google.com/jsapi?key=<?php echo GOOGLE_API_KEY;?>" type="text/javascript"></script>
  
</head>

<body id="editListBody" >
<p>
<!-- CONTENT: Holds all site content except for the footer.  This is what causes the footer to stick to the bottom -->
<div id="content" class="width100">
  
    	<table id="subscribe_list">
    		<tbody>
      <?php
	  	
		  	foreach($sub_categories as $category_key=>$categories_val)
			{
				if(!empty($categories_val[0])){
					foreach($categories_val as $sub_category_key=>$category){
						echo '<tr>';
							echo '<td class="title" id="feed_title_'.$category_key.'_'.$sub_category_key.'">'.$category['title'].'</td>';
							echo '<td class="rename" id="rename_button_'.$category_key.'_'.$sub_category_key.'"><input type="button" value="重新命名" onclick="showRenameTitle(\''.$category_key.'\',\''.$sub_category_key.'\')"/></td>';
							echo '<td id="unsubscribe_'.$category_key.'_'.$sub_category_key.'"><img src="styles/images/icons/unsubscribe.png" style="cursor:pointer;" onclick="deleteSubscription(\''.$category_key.'\',\''.$sub_category_key.'\')"/></td>';
							echo '<td><select id="feed_category_'.$category_key.'_'.$sub_category_key.'" onchange="changeCategory(this,\''.$category_key.'\',\''.$sub_category_key.'\')">';
							foreach($categories as $cate_key=>$cate_val){
								if($category_key == $cate_key){
									echo '<option selected value="'.$cate_key.'">'.$cate_val.'</option>';
								}
								else{
									echo '<option value="'.$cate_key.'">'.$cate_val.'</option>';	
								}
								
							}
							echo '</select><span style="display:none;" id="loading_img_'.$category_key.'_'.$sub_category_key.'"><img src="../styles/images/ui-anim_basic_16x16.gif"/></span></td>';
						echo '</tr>';
						echo '<tr class="feed-row"><td colspan="4">'.$category['url'].'</td></tr>';
					}
				}
			}
		
	  ?>
	  	</tbody>
	  </table>
</div>
<div>
    <span><input type="text" id="feedUrl" name="QUERY_URL"/></span>
	<span><input type="button" value="新增訂閱" id="addFeedButton" onclick="addFeed();"/></span>
</div>
</p>
</body>

</html>